package com.ruoyi.project.system.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysStore;
import com.ruoyi.project.system.service.ISysStoreService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 店仓档案Controller
 * 
 * @author anan
 * @date 2021-03-02
 */
@RestController
@RequestMapping("/base/store")
public class SysStoreController extends BaseController
{
    @Autowired
    private ISysStoreService storeService;

    /**
     * 查询店仓档案列表
     */
    @PreAuthorize("@ss.hasPermi('base:store:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysStore sysStore)
    {
        startPage();
        List<SysStore> list = storeService.selectSysStoreList(sysStore);
        return getDataTable(list);
    }

    /**
     * 导出店仓档案列表
     */
    @PreAuthorize("@ss.hasPermi('base:store:export')")
    @Log(title = "店仓档案", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysStore sysStore)
    {
        List<SysStore> list = storeService.selectSysStoreList(sysStore);
        ExcelUtil<SysStore> util = new ExcelUtil<SysStore>(SysStore.class);
        return util.exportExcel(list, "store");
    }

    /**
     * 获取店仓档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:store:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(storeService.selectSysStoreById(id));
    }

    /**
     * 新增店仓档案
     */
    @PreAuthorize("@ss.hasPermi('base:store:add')")
    @Log(title = "店仓档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysStore sysStore)
    {
        return toAjax(storeService.insertSysStore(sysStore));
    }

    /**
     * 修改店仓档案
     */
    @PreAuthorize("@ss.hasPermi('base:store:edit')")
    @Log(title = "店仓档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysStore sysStore)
    {
        return toAjax(storeService.updateSysStore(sysStore));
    }

    /**
     * 删除店仓档案
     */
    @PreAuthorize("@ss.hasPermi('base:store:remove')")
    @Log(title = "店仓档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storeService.deleteSysStoreByIds(ids));
    }

    /**
     * 根据经销商ID获取店仓
     * @param roleId
     * @return
     */
    @GetMapping("/storeTreeselect/{customerId}")
    public AjaxResult storeTreeselect(@PathVariable("customerId") Long customerId)
    {
        AjaxResult ajax = AjaxResult.success();
        SysStore store=new SysStore();
        store.setCCustomerId(customerId);
        store.setIsactive("Y");
        store.setCStorekindId(1L);
        ajax.put("stores", storeService.selectSysStoreList(store));
        return ajax;
    }
}
